package org.amphiprion.kidcalendar.tool;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.amphiprion.kidcalendar.entity.Kid;
import org.amphiprion.kidcalendar.entity.Period;

public class WhoIsPresence {

	public static List<Kid> getPresence(Date date, ArrayList<Kid> kids) {
		// get tomorrow
		Calendar now = Calendar.getInstance();
		now.setTime(date);
		now.set(Calendar.HOUR_OF_DAY, 11);
		now.set(Calendar.MINUTE, 0);
		now.set(Calendar.SECOND, 0);

		// now is the next Saturday
		// System.out.println("Kids nb=" + kids.size());
		ArrayList<Kid> presenceKids = new ArrayList<Kid>();
		for (Kid kid : kids) {
			// System.out.println(">>>>>>>>>>>> START kid:" + kid.getName());
			Period pResult = RuleEvaluator.evaluate(now.getTime(), kid.getRuleGroup().getRules());
			if (pResult != null) {
				presenceKids.add(kid);
			}
			// System.out.println(">>>>>>>>>>>> End kid:" + kid.getName());
		}
		// System.out.println(">>>>>>>>>>>> " + presenceKids);
		return presenceKids;
	}

}
